#pragma once
#ifndef __Player_h_
#define __Player_h_

#include "OgreBulletDynamics.h"
#include <OIS/OIS.h>
#include "Ogre.h"

class Player
{
public:
	Player(Ogre::SceneManager*, OgreBulletDynamics::DynamicsWorld*, Ogre::Vector3 kartPosition, std::vector<TimingGate> *gates, Real *raceTime, bool kbSteering);
	~Player();
	void steerKart(OIS::Keyboard* mKeyboard); //for keyboard steering
	void steerKart(float dir); //for controller or wheel steering
	void accelerateOrBrake(float dir); //for controller or wheel acceleration/braking
	bool update(Ogre::Real elapsedTime, GameState state);
	void toggleKbSteering();
	Ogre::Vector3 getDriverPosition();
	Ogre::Quaternion getOrientation();
	Ogre::Real getVelocity();
	void attachSoundtoEngine(String soundName, OgreOggSound::OgreOggSoundManager *soundMngr);
	int getCurrentLap();
	int getLastTimingGate();
	Real getLastTimingGateTime();
	Real getBestLapTime();
	Real getPrevLapTime();
	bool shouldDisplayPrevLapTime();
	void resetPrevLapTimeDisplay();
private:
	Ogre::SceneManager* mSceneMgr;
	OgreBulletDynamics::DynamicsWorld *mWorld;
	GameState mGameState;
	std::vector<TimingGate> *mTimingGates;
	Real *mRaceTime;
	int mCurrLap;
	std::vector<Real> mLastTimeAtTimingGate;
	int mNextGate;
	Real mBestLapTime;
	Real mPrevLapTime;
	Real mLapStartTime;
	bool mPrevLapDisplaying;

	OgreBulletDynamics::WheeledRigidBody        *mCarChassis;
    OgreBulletDynamics::VehicleTuning	        *mTuning;
    OgreBulletDynamics::VehicleRayCaster	    *mVehicleRayCaster;
    OgreBulletDynamics::RaycastVehicle	        *mVehicle;

    Ogre::Entity    *mChassis;
	Ogre::Entity    *mSteeringWheel;
    Ogre::Entity    *mWheels[4];
	Ogre::SceneNode *mChassisNode;
	Ogre::SceneNode *mSteeringWheelNode;
	Ogre::SceneNode *mWheelNodes[4];
	Ogre::SceneNode *mEngineNode;

	int mWheelsEngine[4];
	int mWheelsEngineCount;
	int mWheelsSteerable[4];
	int mWheelsSteerableCount;
	float mEngineForce;
	float mBrakeForce;
	float mSteering;
	float mSteeringTarget;
	int mWheelEngineStyle;
	int mWheelSteeringStyle;
	bool kbSteeringEnabled;
	bool mSteeringLeft;
	bool mSteeringRight;

	bool createKart(Ogre::Vector3 kartPosition);
	void incNextGate();
	float distanceToNextTimingGate();
	void updateGateTimers();
};

#endif // #ifndef __Player_h_